package org.scs.carleton.ca.pgdt.core.ui.internal.highlighting;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

/**
 * The colour manager is what is responsible for managing all of the colours and ensuring that they are disposed.
 *
 *
 * @author jtessier
 *
 * @version 1.0
 */
public class ColorManager {
	protected Map<RGB, Color> colorTable;
	
	public ColorManager() {
		colorTable = new HashMap<RGB, Color>(10);
	}

	public void dispose() {
		for (Color color : colorTable.values()) {
			color.dispose();
		}
	}
	
	public Color getColor(RGB rgb) {
		Color color = colorTable.get(rgb);
		if (color == null) {
			color = new Color(Display.getCurrent(), rgb);
			colorTable.put(rgb, color);
		}
		return color;
	}
}
